﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using MindFusion.Scheduling;
using System.Threading;

namespace DentistApplication
{
    /// <summary>
    /// Interaction logic for PatientWindow.xaml
    /// </summary>
    public partial class RegistrationWindow : Window
    {

        public RegistrationWindow()
        {
            InitializeComponent();

        }

        #region PATIENT


        private void bt_addPatient_Click(object sender, RoutedEventArgs e)
        {
            string helpp = box_sex.SelectedValue.ToString();
            string[] help = helpp.Split(new string[] {": "}, System.StringSplitOptions.RemoveEmptyEntries);

            TextRange tr = new TextRange(box_otherInfo.Document.ContentStart, box_otherInfo.Document.ContentEnd);
            Patient p = new Patient()
            {
                lastname = box_patientLastname.Text,
                firstname = box_patientName.Text,
                sex = help[1][0],
                birthdate = (DateTime)box_patientBirthDate.SelectedDate,
                phoneNumber = box_phoneNr.Text,
                mobileNumber = box_mobileNr.Text,
                emailAddress = box_emailAdd.Text,
                pesel = box_patientPesel.Text,
                notes = tr.Text
                //box_street.Text,
                //box_zipCode.Text,
                //box_city.Text,
                //box_otherInfo.ToString(),
                //box_bloodGroup.Text))
            };

            if (DatabaseHandler.addPatientToDatabase(p))
            {
                MessageBox.Show("Pacjent został dodany");
                this.Close();
            }
            else
                MessageBox.Show("Wystapił bład");        
            }

        #endregion


        private void bt_cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void ribbonGroup_registration_MouseUp(object sender, MouseButtonEventArgs e)
        {
            grid_newPatientRegistration.Visibility = Visibility.Visible;
            panel_AdditionalPatientData.Visibility = Visibility.Hidden;
            
            
        }

        private void ribbonGroup_additional_MouseUp(object sender, MouseButtonEventArgs e)
        {
            panel_AdditionalPatientData.Visibility = Visibility.Visible;
            grid_newPatientRegistration.Visibility = Visibility.Hidden;
            
        }

        private void la_addPicture_MouseDown(object sender, MouseButtonEventArgs e)
        {
            // Configure open file dialog box
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName = "Picture"; // Default file name
            dlg.DefaultExt = ".jpg"; // Default file extension
            dlg.Filter = "Pictures (.jpg)|(*.JPG)|(*.png)|(*.PNG)|(*.BMP)|(*.bmp)"; // Filter files by extension

            // Show open file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                image_patient.Source = new BitmapImage(new Uri(filename, UriKind.Relative)); 
            }
        }

        private void box_otherInfo_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
      
    }
}
